package com.example;

import java.sql.*;

public class lianjieDao {
    static final String User = "root";
    static final String password = "123456";
    static final String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC";

    public static Connection getconnection() {
        Connection co = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            try {
                co = DriverManager.getConnection(url, User, password);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return co;
    }

    public static void close(Connection connection, Statement statement, ResultSet resultSet) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
